#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

#include <time.h>
#include <ctype.h>
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include "os_api.h"
#include "ps_api.h"
#include "dev_api.h"
#include "debug.h"
#include "sockets.h"
#include "def.h"
#include "netdb.h"
#include "socket_service.h"

#define _TASK_STACK_SIZE    (1024*5)
static void* _task_stack = NULL;
static OSTaskRef _task_ref = NULL;

extern void test_service_init(void);

void wait_network_ready(void)
{
    int count = 30;
    while(count-- && ps_GetNetworkReady() == FALSE){	
        OSATaskSleep(200);
    }

    if (count <= 0){
        LOG_PRINTF("dev_CtrlReset.\n");
        // 判定如果处于生产模式时（需要写号校准），不要重启模块，主要针对提供固件给原厂生产的场景，重启会影响生产
        if (dev_IsProductionMode()){
            dev_CtrlReset(0);
        }

    }
}

static void _task(void *ptr)
{
    test_service_init();
}

int main(void)
{
    int ret;

    _task_stack = malloc(_TASK_STACK_SIZE);
    ASSERT(_task_stack != NULL);

    ret = OSATaskCreate(&_task_ref, _task_stack, _TASK_STACK_SIZE, 85, "test-task", _task, NULL);
    ASSERT(ret == OS_SUCCESS);
    
    return 0;
}